package org.sharelife.interceptor;

import java.util.Map;

import org.sharelife.commons.Constants;
import org.sharelife.entity.User;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;

@SuppressWarnings("serial")
public class AuthorityInterceptor implements Interceptor {

	@Override
	public void destroy() {
	}

	@Override
	public void init() {
	}

	@SuppressWarnings("unchecked")
	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		Map session = invocation.getInvocationContext().getSession();
		User user = (User) session.get(Constants.LOGINUSER);
		System.out.println(user);
		if (null != user) {
			return invocation.invoke();
		} else {
			return Action.LOGIN;
		}
	}
}